using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using bitzhuwei.Compiler;

namespace bitzhuwei.AnsiCFormat {
    /// <summary>
    /// Correspond to the Vn node struct_declaration_list in the grammar(AnsiC).
    /// </summary>
    internal partial class Vnstruct_declaration_list : IFullFormatter {
        // [108]=struct_declaration_list : struct_declaration ;
        // [109]=struct_declaration_list : struct_declaration_list struct_declaration ;

        private readonly Vnstruct_declaration first0;
        private readonly List<Vnstruct_declaration> list0 = new();
        private readonly TokenRange _scope;

        public TokenRange Scope => _scope;

        public void Format(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }

        public void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context) {
            {
                context.PrintBlanksAnd(this.first0, preConfig, writer);
            }
            var first = true;
            var config = new BlankConfig(inlineBlank: 1, forceNewline: false);
            for (var i = 0; i < this.list0.Count; i++) {
                var item0 = this.list0[i];
                if (first) {
                    context.PrintCommentsBetween(this.first0, item0, config, writer);
                    first = false;
                }
                else {
                    context.PrintCommentsBetween(this.list0[i - 1], item0, config, writer);
                }
                context.PrintBlanksAnd(item0, config, writer);
            }
        }

        public IEnumerable<string> YieldTokens(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }

        // [108]=struct_declaration_list : struct_declaration ;
        // dumped by ListExtractor 1
        internal Vnstruct_declaration_list(Vnstruct_declaration first0) {
            this.first0 = first0;
            this._scope = new TokenRange(first0);
        }
        // [109]=struct_declaration_list : struct_declaration_list struct_declaration ;
        // dumped by ListExtractor 2
        internal void Add(Vnstruct_declaration r0) {
            this.list0.Add(r0);
            this._scope.end = r0.Scope.end;
        }

    }
}
